//
//  MainViewController.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/13.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    //MARK:- 生命周期方法
    //按钮在view即将显示的时候添加 设置尺寸
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //添加按钮
        tabBar.addSubview(composeButton)
        //计算 设置按钮尺寸
        let width = tabBar.frame.size.width / CGFloat(childViewControllers.count)
        composeButton.frame = CGRect(x: 2 * width, y: 0, width: width, height: 44)
        //计算按钮的中心位置
        let size = tabBar.frame.size
        composeButton.center = CGPoint(x: size.width / 2, y: size.height / 2)
    }
    

    //MARK: - 内部控制方法
    @objc private func composeButtonClik(btn: UIButton){
        ZHLog(btn)
    }
    
    //MARK: - 懒加载
    private lazy var composeButton: UIButton = {
        () -> UIButton in
        //创建按钮
        let button = UIButton(image: "tabbar_compose_icon_add", backgroundImage: "tabbar_compose_button")
        //添加监听点击
        button.addTarget(self, action: #selector(composeButtonClik(btn:)), for: UIControlEvents.touchUpInside)
        return button
    }()
    

}
